package com.jy.api.controller.admin;

import com.jy.api.service.CashCouponService;
import com.jy.api.service.CashCouponTransactionService;
import com.jy.api.signUpReq.admin.CashCouponReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * Created by xiaohua on 2019/1/18.
 */
@RequestMapping(value = "v1/admin/", produces = "application/json;charset=utf-8")
@RestController
@Slf4j
public class CashCouponController {

    @Autowired
    private CashCouponService cashCouponService;
    @Autowired
    private CashCouponTransactionService service;


    @PostMapping("add-coupon")
    public ResponseEntity addCashCoupon(@RequestBody CashCouponReq req,Principal principal) {
        return ResponseEntity.ok(cashCouponService.addCashCoupon(req,principal));
    }

    @GetMapping("all-coupon")
    public ResponseEntity getAllCoupon(@RequestParam("storeId") String storeId) {
        return ResponseEntity.ok(cashCouponService.findAllCoupon(storeId));
    }

    @PostMapping("update-coupon")
    public ResponseEntity updateCoupon(@RequestBody CashCouponReq req) {
        return ResponseEntity.ok(cashCouponService.updateCouponById(req));

    }

    @PostMapping("delete-coupon")
    public ResponseEntity deleteCoupon(@RequestBody CashCouponReq req) {
        return ResponseEntity.ok(cashCouponService.deleteCouponById(req));
    }

    @GetMapping("get-tran")
    public ResponseEntity getTran(@RequestParam("storeId") String storeId, Pageable pageable, @RequestParam("type") String type) {
        return ResponseEntity.ok(service.findAllByStoreId(storeId, type, pageable));
    }

    @GetMapping("get-memberCash")
    public ResponseEntity getTran(@RequestParam("memberId") String memberId, @RequestParam("storeId") String storeId) {
        return ResponseEntity.ok(service.findAllByMemberCash(memberId, storeId));
    }


}
